package com.soft.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.BeanUtils;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Component;

import com.soft.dao.AssistDao;
import com.soft.front.dto.FAssistDTO;
import com.soft.model.Assist;

@SuppressWarnings("unchecked")
@Component
public class AssistDaoImpl extends BaseDaoImpl implements AssistDao {

	@CacheEvict(value = "ASSIST_INFO_CACHE", allEntries = true)
	public void addOrEdit(Assist assist) {
		this.saveOrUpdate(assist);
	}

	@CacheEvict(value = "ASSIST_INFO_CACHE", allEntries = true)
	public void remove(Assist assist) {
		this.delete(assist);
	}

	@Cacheable(value = "ASSIST_INFO_CACHE")
	public Map<String, Object> get() {
		Map<String, Object> resMap = new HashMap<String, Object>();
		List<Assist> assistLst = this.findAll(Assist.class, null);
		for (Assist assist : assistLst) {
			FAssistDTO dto = new FAssistDTO();
			BeanUtils.copyProperties(assist, dto);
			resMap.put(assist.getNamespace(), dto);
		}
		return resMap;
	}

}
